<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\facade\Session;
class Index extends Controller
{
   public function login(){
        if(request()->isPost()){
            $data = input('post.');
            $admin  = db('user')->where(['name'=>$data['name'],'pass'=>$data['password'],'is_admin'=>1])->find();
            if(empty($admin)){
                    $this->error('管理员不存在或密码错误');
            }else{
                Session::set('admin',$admin);
                $this->success('登录成功','/admin/index/index');
            } 
        }

       return view();
   }

   public function logout(){
    Session::delete('admin');
    $this->success('退出成功','/admin/index/login');
   }

   public function index(){
    $admin=session('admin');
    if(empty($admin)){
        $this->error('您未登录，不能进去后台管理','/admin/index/login');
    }
       $this->assign('numleft',0);
       return view();
   }
}